<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">品牌名称</label>
        <el-input
          v-model="query.brandName"
          clearable
          placeholder="品牌名称"
          style="width: 185px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="600px"
      >
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
          <el-form-item label="品牌名称" prop="brandName">
            <el-input v-model="form.brandName" style="width: 370px;" />
          </el-form-item>
          <!--   <el-form-item label="品牌图标 url">
               <el-input v-model="form.brandIcon" style="width: 370px;" />
             </el-form-item>
             <el-form-item label="品牌banner url">
               <el-input v-model="form.backgroundImage" style="width: 370px;" />
             </el-form-item>-->
          <el-form-item label="品牌描述">
            <el-input v-model="form.brandTitle" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="品牌详情">
            <el-input v-model="form.detailInfo" style="width: 370px;" />
          </el-form-item>

          <el-form-item label="排序">
            <el-input v-model="form.orderSort" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="是否展示">
            <el-radio v-model="form.isShow" :label="true">是</el-radio>
            <el-radio v-model="form.isShow" :label="false">否</el-radio>
          </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="id" />
        <el-table-column prop="brandName" label="品牌名称" />
        <!--<el-table-column prop="brandIcon" label="品牌图标 url"/>
        <el-table-column prop="backgroundImage" label="品牌banner url"/>-->
        <el-table-column prop="detailInfo" label="品牌详情（简介）" />
        <el-table-column prop="isShow" label="是否展示 1是 0否">
          <template slot-scope="scope">
            {{ dict.label.status[scope.row.isShow] }}
          </template>
        </el-table-column>
        <el-table-column prop="brandTitle" label="品牌描述" />
        <el-table-column prop="orderSort" label="排序" />
        <el-table-column v-permission="['admin','ycBrand:edit','ycBrand:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudYcBrand from '@/api/goods/goodsBrand'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = {
  id: null,
  brandName: null,
  brandIcon: null,
  backgroundImage: null,
  detailInfo: null,
  isShow: null,
  brandTitle: null,
  orderSort: null
}
export default {
  name: 'YcBrand',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['status'],
  cruds() {
    return CRUD({ title: '商品品牌', url: 'api/ycBrand', sort: 'id,desc', crudMethod: { ...crudYcBrand }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'ycBrand:add'],
        edit: ['admin', 'ycBrand:edit'],
        del: ['admin', 'ycBrand:del']
      },
      rules: {
        brandName: [
          { required: true, message: '品牌名称不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'brandName', display_name: '品牌名称' },
        { key: 'detailInfo', display_name: '品牌详情（简介）' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    // 编辑 - 之前
    [CRUD.HOOK.beforeToEdit]() {
      console.log('form============')
      console.log(this.form)
      return true
    }
  }
}
</script>

<style scoped>

</style>
